package com.zdp.filesync.monitor;

import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;

import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池对象 --> 执行 文件监听任务
 *
 */
public class FileMonitorPool {

    public static  ThreadPoolExecutor executor;

    private FileMonitorPool(){}


    public static ThreadPoolExecutor getExecutor(){
        if(Objects.isNull(executor)){
            initExecutor();
        }
        return executor;
    }

    private static void initExecutor(){
            executor = new ThreadPoolExecutor(10, 20, 10,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<>(10),
                    new ThreadPoolExecutor.AbortPolicy());
    }

    public static void shutdown(){
        if(Objects.nonNull(executor)){
            executor.shutdown();
        }
    }


}
